
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>公告列表</title>

    <link type="text/css" rel="stylesheet" href="js/jquery-easyui-1.5.3/themes/default/easyui.css"/>
    <link type="text/css" rel="stylesheet" href="js/jquery-easyui-1.5.3/themes/icon.css"/>
    <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/css/main.css">
</head>
<body >

<div class="tableFind">
            <!-- <p><label>标题</label><input type="text" id="user"/> -->
            <p>
				
				<label>公告标题</label>&nbsp;&nbsp;
				<input type="text" id="noticeTitle"  onkeydown="if(event.keyCode==13) searchMessage()"/> 
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
				<a id="btn"
					href="javascript:searchnoticeTitle()" class="easyui-linkbutton tableFindBut"
					data-options="iconCls:'icon-search'" onclick="obj.find()">查询	
			    </a>
			</p> 	
            
        </div>

<table id="user_dg" class="easyui-datagrid" style="height: 470px;"
		url="${pageContext.request.contextPath}/admin/Notice/findAll.do" toolbar="#user_toolbar" pagination="true"
		rownumbers="true" fitColumns="true" singleSelect="true"
		data-options="fit:false,border:false,pageSize:10,pageList:[10,20,30,40]">
		<thead>
		
		<!-- 管理表格-表头的修改 -->
			<tr>
			<th field="cb" checkbox="true" align="center"></th>
            <th field="noticeNo" width="80" align="center">公告编号</th>
            <th field="noticeAuthor" width="80" align="center">发布作者</th>
            <th field="noticeTitle" width=150 align="center">公告标题</th>
            <th field="noticeContent" width="150" align="center">公告内容</th>
            <th field="publishTime" width="150" align="center">发布时间</th>
			</tr>
		</thead>
	</table>
	<div id="user_toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="newUserMessage()">新增</a>  <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroyUserMessage()">删除</a>
	</div>
	<div id="user_dlg" class="easyui-dialog" style="padding: 10px 20px";
		closed="true" buttons="#user_dlg-buttons">
		<div class="ftitle">详细信息</div>
		<form id="user_fm" method="post" novalidate>
			<div class="fitem">
				<label>发布作者:</label> <input name="noticeAuthor" class="easyui-textbox"
					required="true">
			</div>
			<div class="fitem">
				<label>公告标题:</label> <input name="noticeTitle" class="easyui-textbox"
					required="true">
			</div>
			<div class="fitem">
				<label>公告内容:</label> <input name="noticeContent" class="easyui-textbox">
			</div>
			<div class="fitem">
				<label>发布时间:</label> <input name="publishTime" class="easyui-datebox"
					validType="date">
			</div>
		</form>
	</div>
	<div id="user_dlg-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton c6"
			iconCls="icon-ok" onclick="saveUserMessage()" style="width: 90px">保存</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#user_dlg').dialog('close')"
			style="width: 90px">取消</a>
	</div>
	<script type="text/javascript">
	 
	//模糊查询
	function searchnoticeTitle() {
		$('#user_dg').datagrid('load', {
			noticeTitle : $('#noticeTitle').val()
		});
	}
	
	
	//重新设置easy ui的时间格式
	$.fn.datebox.defaults.formatter=function(date){
		var y=date.getFullYear();
		var m=date.getMonth()+1;
		var d=date.getDate();
		return y+'/'+m+'/'+d;
	}
	$.fn.datebox.defaults.parser=function(date){
		if(date){
			return new Date(date)
		}else{
			return new Date();
		}
	}
	
		var url;
		function newUserMessage() {
			$('#user_dlg').dialog('open').dialog('setTitle', '新增');
			$('#user_fm').form('clear');//清除表单数据
			url = '${pageContext.request.contextPath}/admin/Notice/addNotice.do';//新增调用的网址
		}
		function editUserMessage() {
			var row = $('#user_dg').datagrid('getSelected');
			if (row) {
				$('#user_dlg').dialog('open').dialog('setTitle', '编辑');
				$('#user_fm').form('clear');//清除表单数据
				$('#user_fm').form('load', row);
				url = '${pageContext.request.contextPath}/admin/Notice/updateNotice.do?noticeNo=' + row.noticeNo;
			}
		}
		function saveUserMessage() {
			$('#user_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.errorMsg) {
						$.messager.show({
							title : 'Error',
							msg : result.errorMsg
						});
					} else {
						$('#user_dlg').dialog('close'); // close the dialog
						$('#user_dg').datagrid('reload'); // reload the user data
					}
				}
			});
		}
		function destroyUserMessage() {
			var row = $('#user_dg').datagrid('getSelected');
			if (row) {
				$.messager.confirm('Confirm', '确定要删除吗?', function(r) {
					if (r) {
						//ajax调用--异步通信调用
						$.post('${pageContext.request.contextPath}/admin/Notice/deleteNotice.do', {
							noticeNo : row.noticeNo
						}, function(result) {
							if (result.success) {
								$('#user_dg').datagrid('reload'); // reload the user data
							} else {
								$.messager.show({ // show error message
									title : 'Error',
									msg : result.errorMsg
								});
							}
						}, 'json');//回调函数
					}
				});
			}
		}
		
	</script>

<script src="js/jquery-easyui-1.5.3/jquery.min.js"></script>
<script src="js/jquery-easyui-1.5.3/jquery.easyui.min.js"></script>
<script src="js/jquery-easyui-1.5.3/locale/easyui-lang-zh_CN.js"></script>
<script src="js/user.js"></script>


</body>
</html>